﻿using B.Auth.APi.Application.Command.Role;
using B.Auth.Domain.Entity;
using B.Auth.Domain.Repository;
using B.Auth.Enum;
using MediatR;

namespace B.Auth.APi.Application.CommandHand.Role
{
    
    public class GetRoleCommandHand : IRequestHandler<GetRoleCommand, ApiResult<List<RoleModel>>>
    {
        private readonly IBaseRepository<RoleModel> roledb;

        public GetRoleCommandHand(IBaseRepository<RoleModel> roledb)
        {
            this.roledb = roledb;
        }

        public Task<ApiResult<List<RoleModel>>> Handle(GetRoleCommand request, CancellationToken cancellationToken)
        {

            var result= new ApiResult<List<RoleModel>>();
            var m = roledb.GetAll().Where(x=>x.Del==0).OrderByDescending(x=>x.Id).ToList();
            

            result.data = m;
            
            return Task.FromResult(result);
            
        }
    }
}
